package com.cictec.middleware.gps.engine.event.listener;

import javax.annotation.PostConstruct;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.cictec.middleware.commons.utils.PMSUtils;
import com.cictec.middleware.core.entity.BusDriverSignIn;
import com.cictec.middleware.gps.engine.TimeEventBus;
import com.cictec.middleware.gps.engine.event.DriverSignEvent;
import com.cictec.middleware.gps.service.ScheduleService;
import com.google.common.eventbus.Subscribe;


/**
 * 设备上下线 事件处理监听【中间件外部事件】
 * @author Administrator
 *
 */
@Component
public class DriverSignEventListener {
	
	private static Logger logger = LoggerFactory.getLogger(DriverSignEventListener.class);
	
	@Autowired
	private TimeEventBus timeEventBus;
	@Autowired
	private ScheduleService scheduleService;
	
	@PostConstruct
	public void init() {
		logger.debug("注册【DriverSignEventListener】到TimeEventBus， 监听器：DeviceOnlineOfflineListener ---> 事件：DriverSignEvent");
		timeEventBus.register(this);

	}
	
	/**
	 * 更新 设备在线、离线状态
	 * @param event
	 */
	@Subscribe
	public void onHandler(DriverSignEvent event){
		logger.debug(" 【DriverSignEventListener】");
		
		BusDriverSignIn signIn = event.getBusDriverSignIn();
		
		// 更新线路指定日期，排班表后所有司机
		if(PMSUtils.isEmpty(signIn.getSignLineUuid())){
//			return;
		}
		scheduleService.updateScheduleDriver(event.getTime(), signIn.getSignLineUuid(), signIn.getBusUuid(), signIn.getSignDrvUuid());
		
		
	}
	

}
